package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.CertificateInfoDO;
import com.jinzhi.jzweb.service.CertificateInfoService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2024-05-15 17:22:11 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/certificateInfo")
public class CertificateInfoController extends BaseController {
	@Autowired
	private CertificateInfoService certificateInfoService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:certificateInfo:certificateInfo")
	String CertificateInfo(){
	    return "jzweb/certificateInfo/certificateInfo";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:certificateInfo:certificateInfo")
	public Result<Page<CertificateInfoDO>> list(CertificateInfoDO certificateInfoDTO){
		// 查询列表数据
		Page<CertificateInfoDO> page = certificateInfoService.selectPage(getPage(CertificateInfoDO.class),
					certificateInfoService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				CertificateInfoDO obj = (CertificateInfoDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:certificateInfo:add")
	String add(){
	    return "jzweb/certificateInfo/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:certificateInfo:edit")
	String edit(@PathVariable("id") Long id,Model model){
		CertificateInfoDO certificateInfo = certificateInfoService.selectById(id);
		model.addAttribute("certificateInfo", certificateInfo);
	    return "jzweb/certificateInfo/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:certificateInfo:add")
	public Result<String> save( CertificateInfoDO certificateInfo){
		certificateInfoService.insert(certificateInfo);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:certificateInfo:edit")
	public Result<String>  update( CertificateInfoDO certificateInfo){
		boolean update = certificateInfoService.updateById(certificateInfo);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:certificateInfo:remove")
	public Result<String>  remove( Long id){
		certificateInfoService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:certificateInfo:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		certificateInfoService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
